package miracle.joker.design.composite;

import java.util.ArrayList;
import java.util.List;

public class Composite implements Component {
    private List<Component> components = new ArrayList<Component>();

    public void add(Component component) {
        components.add(component);
    }

    public void remove(Component component) {
        components.remove(component);
    }

    public Component getChild(int index) {
        return components.get(index);
    }

    public int getSalary() {
        int salary = 0;
        for (Component component : components) {
            salary += component.getSalary();
        }
        return salary;
    }
}
